<script setup>
import { ref } from 'vue'
const props = defineProps({
  list: Array
})

const emits = defineEmits(['changeActive'])

// 1. 点击切换active状态
const active = ref(0)
const setActive = (index) => {
  active.value = index
  emits('changeActive', index)
}
</script>

<template>
  <ul class="nav">
    <li
      v-for="(item, index) in props.list"
      :key="index"
      class="item"
      :class="{ active: active === index }"
      @click="setActive(index)"
    >
      {{ item.title }}
    </li>
  </ul>
</template>

<style lang="less" scoped>
@theme-color: #00a98f;
.nav {
  display: flex;
  flex-direction: column;
  justify-content: space-start;
  gap: 1px;
  // margin-left: 10px;
  width: 100px;
  height: 90vh;
  // margin-top: 5px;
  .item {
    background-color: @theme-color;
    width: 100px;
    height: 30px;
    border-radius: 5px;
    color: white;
    text-align: center;
    line-height: 30px;
    list-style-type: none;
    &:hover {
      background-color: lighten(@theme-color, 10%);
      cursor: pointer;
    }
  }
  .active {
    background-color: lighten(@theme-color, 10%);
  }
}
</style>
